home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Sound / Amster / Source / url.c < prev   
Encoding:
C/C++ Source or Header  |  2001-03-11  |  4.4 KB  |  165 lines

  1. /*
  2. ** Amster - Clickable URL Class
  3. ** Copyright © 2000 by Gürer Özen
  4. **
  5. ** This program is free software; you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation; either version 2 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program; if not, write to the Free Software
  17. ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  18. */
  19.  
  20. #include "config.h"
  21.  
  22. #include <string.h>
  23.  
  24. #include "mui.h"
  25. #include <proto/graphics.h>
  26. #include <proto/openurl.h>
  27.  
  28. #include "url.h"
  29.  
  30. struct Library *OpenURLBase;
  31.  
  32. ULONG url_new(struct IClass *cl, Object *obj, struct opSet *msg);
  33. ULONG url_setup(struct IClass *cl, Object *obj, Msg msg);
  34. ULONG url_minmax(struct IClass *cl, Object *obj, struct MUIP_AskMinMax *msg);
  35. ULONG url_draw(struct IClass *cl, Object *obj, struct MUIP_Draw *msg);
  36. ULONG url_cleanup(struct IClass *cl, Object *obj, Msg msg);
  37. ULONG url_clicked(struct IClass *cl, Object *obj, Msg msg);
  38.  
  39.  
  40. MUI_DISPATCH(url_dispatch)
  41. {
  42.     switch(msg->MethodID) {
  43.         case OM_NEW:         return(url_new(cl,obj,(APTR)msg));
  44.         case MUIM_Setup:     return(url_setup(cl,obj,(APTR)msg));
  45.         case MUIM_AskMinMax: return(url_minmax(cl,obj,(APTR)msg));
  46.         case MUIM_Draw:      return(url_draw(cl,obj,(APTR)msg));
  47.         case MUIM_Cleanup:   return(url_cleanup(cl,obj,(APTR)msg));
  48.         case URL_CLICKED:    return(url_clicked(cl,obj,(APTR)msg));
  49.     }
  50.     return(DoSuperMethodA(cl,obj,msg));
  51. }
  52.  
  53.  
  54. ULONG url_new(struct IClass *cl, Object *obj, struct opSet *msg)
  55. {
  56.     struct urldata *data;
  57.     char *name, *href;
  58. /*    char *help;*/
  59.  
  60.     name = (char *)GetTagData(URL_NAME,0,msg->ops_AttrList);
  61.     href = (char *)GetTagData(URL_HREF,0,msg->ops_AttrList);
  62. /*    help = (char *)GetTagData(URL_HELP,0,msg->ops_AttrList);*/
  63.  
  64.     obj = (Object *)DoSuperNew(cl,obj,
  65.         MUIA_Font, MUIV_Font_Button,
  66.         MUIA_ShowSelState, FALSE,
  67.         MUIA_InputMode, MUIV_InputMode_RelVerify,
  68.         /* MUIA_ShortHelp, help, */
  69.         TAG_MORE, msg->ops_AttrList);
  70.  
  71.     if(!obj) return(NULL);
  72.  
  73.     data = INST_DATA(cl,obj);
  74.     data->name = name;
  75.     data->href = href;
  76.     data->len = strlen(name);
  77.     data->color = -1;
  78.  
  79.     DoMethod(obj,MUIM_Notify,MUIA_Pressed,FALSE,obj,1,URL_CLICKED);
  80.     return((ULONG)obj);
  81. }
  82.  
  83.  
  84. ULONG url_setup(struct IClass *cl, Object *obj, Msg msg)
  85. {
  86.     struct urldata *data = INST_DATA(cl,obj);
  87.  
  88.     if (!DoSuperMethodA(cl,obj,msg))
  89.         return(FALSE);
  90.  
  91.     data->color = ObtainBestPen(_screen(obj)->ViewPort.ColorMap,0,0,0,OBP_Precision,PRECISION_GUI,TAG_DONE);
  92.  
  93.     return(TRUE);
  94. }
  95.  
  96.  
  97. ULONG url_minmax(struct IClass *cl, Object *obj, struct MUIP_AskMinMax *msg)
  98. {
  99.     struct urldata *data = INST_DATA(cl,obj);
  100.     int x,y;
  101.  
  102.     DoSuperMethodA(cl,obj,(APTR)msg);
  103.  
  104.     x = _font(obj)->tf_XSize * data->len;
  105.     y = _font(obj)->tf_YSize;
  106.  
  107.     msg->MinMaxInfo->MinWidth  += x;
  108.     msg->MinMaxInfo->DefWidth  += x + (x/10);
  109.     msg->MinMaxInfo->MaxWidth  += MUI_MAXMAX;
  110.     msg->MinMaxInfo->MinHeight += y;
  111.     msg->MinMaxInfo->DefHeight += y;
  112.     msg->MinMaxInfo->MaxHeight += y;
  113.  
  114.     return(0);
  115. }
  116.  
  117.  
  118. ULONG url_draw(struct IClass *cl, Object *obj, struct MUIP_Draw *msg)
  119. {
  120.     struct urldata *data = INST_DATA(cl,obj);
  121.     int x,y,i;
  122.  
  123.     DoSuperMethodA(cl,obj,(APTR)msg);
  124.     if(!(msg->flags & MADF_DRAWOBJECT)) return(0);
  125.  
  126.     SetFont(_rp(obj),_font(obj));
  127.  
  128.     if(!data->pixlen) data->pixlen=TextLength(_rp(obj),data->name,data->len);
  129.     x = _mleft(obj) + ( (_mwidth(obj) - data->pixlen) / 2);
  130.     y = _mtop(obj) + _font(obj)->tf_Baseline + ( (_mheight(obj) - _font(obj)->tf_YSize) / 2 );
  131.  
  132.     Move(_rp(obj),x,y);
  133.     if(data->color != -1) SetAPen(_rp(obj),data->color); else SetAPen(_rp(obj),1);
  134.     Text(_rp(obj),data->name,data->len);
  135.  
  136.     for (i=x; i<=x+data->pixlen; i+=4) {
  137.          Move(_rp(obj), i, y+3);
  138.         Draw(_rp(obj), i+1, y+3);
  139.     }
  140.  
  141.     return(0);
  142. }
  143.  
  144.  
  145. ULONG url_cleanup(struct IClass *cl, Object *obj, Msg msg)
  146. {
  147.     struct urldata *data = INST_DATA(cl,obj);
  148.  
  149.     if(data->color != -1) ReleasePen(_screen(obj)->ViewPort.ColorMap,data->color);
  150.  
  151.     return(DoSuperMethodA(cl,obj,msg));
  152. }
  153.  
  154.  
  155. ULONG url_clicked(struct IClass *cl, Object *obj, Msg msg)
  156. {
  157.     struct urldata *data = INST_DATA(cl,obj);
  158.  
  159.     OpenURLBase = OpenLibrary("openurl.library", 1);
  160.     if (!OpenURLBase) return(0);
  161.     URL_Open(data->href, TAG_DONE);
  162.     CloseLibrary(OpenURLBase);
  163.     return(0);
  164. }
  165.